/**
 * 
 */
package t4j.holding;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.ListIterator;
import java.util.Random;




public class ListIteration {
	public static void main(String[] args) {
		List<Pet> pets = new ArrayList<Pet>();
		
		Collections.addAll(pets, new Pet(1),new Pet(2),new Pet(3),new Pet(4),new Pet(5));
		
		ListIterator<Pet> it = pets.listIterator();
		
		while(it.hasNext()){
			System.out.println(it.next() +". " + it.nextIndex() + ". " +it.previousIndex() + "; ");
		}
		
		System.out.println();
		
		while(it.hasPrevious())
			System.out.println(it.previous().id()+ " ");
		
		System.out.println();
		System.out.println(pets);
		
		it = pets.listIterator(3);
		
		while(it.hasNext()){
			it.next();
			it.set(new Pet(8));
		}
		
		System.out.println(pets);
	}
}
